package com.bbx.taxi.client.Task;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Officail_ComboBuild;
import com.bbx.api.sdk.model.official.passanger.Official_TCBuild;
import com.bbx.api.sdk.model.official.passanger.Official_TCBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Combo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_TC;
import com.bbx.api.sdk.model.official.passanger.Return.Official_Star;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_ComboNet;
import com.bbx.api.sdk.net.official.passanger.Official_StarNet;
import com.bbx.api.sdk.net.official.passanger.Official_TCNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;
/** 
 * @Path com.bbx.taxi.client.Task.MyTCTask.java
 * @Author 严旭文
 * @Date 2016-3-10 下午7:02:17
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class MyTCTask {
	private Activity context;
	public static MyTCTask instance;
	public TCTask mTCTask;
	public static MyTCTask getInstance(Activity context) {
		instance = new MyTCTask(context);
		return instance;
	}
	public MyTCTask(Activity context) {
		this.context = context;
		getTc();
	
	}
	/**
	 * 获取Tc机构
	 */
	public void getTc() {
		Official_TCBuild mOfficial_TCBuild=new Official_TCBuild(context);
		mOfficial_TCBuild.passenger_id=MyApplication.getInstance().getUid();
		TCTask mTCTask=new TCTask(context, mOfficial_TCBuild);
		mTCTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class TCTask extends BaseAsyncTask {

		private Official_TCBuild mOfficial_TCBuild;

		public TCTask(Activity context, Official_TCBuild mOfficial_TCBuild) {
			super(context,false);
			this.mOfficial_TCBuild = mOfficial_TCBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Officail_TC mOfficail_TC=(Officail_TC)object;
				if(mOfficail_TC!=null&&mOfficail_TC.getInfo()!=null){
					String tc_id=mOfficail_TC.getInfo().getTc_id();
					String service_tel=mOfficail_TC.getInfo().getService_tel();
					MainAttribute.getInstance().setTc_id(tc_id);
					if(service_tel!=null&&!service_tel.equals("")){
						Value.TEL_KF=service_tel;
					}
				}
			}
		}

		@Override
		public void onFailed(int status, String msg) {
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_TCBuild).getJson();
			return new Official_TCNet(context, json);
		}
	}

}
